﻿Imports System
Imports MindFusion.Diagramming
Imports DevExpress.XtraGrid.Columns

Public Class UcnGrid
    'represents grid for setting properties of datatable

#Region "Attributes"
#Region "Private attributes"
    Private MbReadyForUse As Boolean = False 'indicates proper initialization of usercontrol
    Private MoItem As DiagramItem = Nothing  'actual selected item
    Private MoOldCellValue As Object = Nothing 'old cell value after value was changed to new value
    Private MoImplicitBaseEditor As DevExpress.XtraEditors.BaseEdit = Nothing 'implicit editor for editing cells - used for immediate accepting changes after click on base editor of cell

    'my own repository controls
    Private MoUcnComboboxDataType As UcnCombobox = Nothing
    Private MoUcnComboboxComponentType As UcnCombobox = Nothing
    Private MoUcnComboboxJoinedModule As UcnCombobox = Nothing
    Private MoUcnComboboxAccess As UcnCombobox = Nothing
    Private MoUcnComboboxValidateType As UcnCombobox = Nothing
#End Region
#End Region
#Region "Events"
    Public Event MMValueChanged(ByVal Column As GridColumn, ByVal NewValue As Object, ByVal OldValue As Object) 'event is raised when value of cell was successfully changed
    Public Event MMCustomDrawCardField(ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) 'field custom drawing
    Public Event MMCustomDrawCardFieldCaption(ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) 'field caption custom drawing
    Public Event MMCustomDrawCardFieldValue(ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) 'field value custom drawing
    Public Event MMShowingEditor(ByVal e As System.ComponentModel.CancelEventArgs) 'event is raised before activating an cell editor
    Public Event MMValueValidating(ByVal Item As Object, ByVal Column As GridColumn, ByRef Value As Object, ByRef Valid As Boolean, ByRef ErrorText As String, ByVal OldValue As Object) 'event is raised while validating new value
    Public Event MMInvalidValueException(ByVal e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) 'event is raised after invalid cell value was entered
    Public Event MMPositionOfNavigatorChanged(ByVal Position As Integer) 'event is raised after position of navigator is changed
    Public Event MMAddItem(ByRef Item As DiagramItem, ByVal NewRowPosition As Integer, ByVal NewDataNavigatorPosition As Integer) 'event is raised when user clicked on add button (before adding new item)
    Public Event MMRemoveItem(ByRef Item As DiagramItem, ByVal ColumnName As String, ByVal NewDataNavigatorPosition As Integer) 'event is raised when user clicked on remove button (before adding new item)
    Public Event MMMoveUp(ByRef Item As DiagramItem, ByVal ColumnName As String) 'event is raised when user clicked on up button (before moving item)
    Public Event MMMoveDown(ByRef Item As DiagramItem, ByVal ColumnName As String) 'event is raised when user clicked on down button (before moving item)
#End Region
#Region "Constructors & Init"
    Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.


        '**********************************************************************
        InitControl()
        '**********************************************************************
    End Sub
    'setting usercontrol settings after it is created
    Private Function InitControl() As GeActionResult
        SetReadyForUse(False) 'disabling usercontrol
        Try
            tlTableLayoutPanel.BackColor = Me.DataNavigator.BackColor
            MoItem = Nothing

            'initialization of my own repository controls
            '--- DataType
            Dim LoTextCollection As Collection = New Collection
            Dim LoIdCollection As Collection = New Collection

            'LoTextCollection.Add("Boolean")
            'LoIdCollection.Add(KrosLib.Data.eDataType.Boolean)
            'LoTextCollection.Add("Cele cislo")
            'LoIdCollection.Add(KrosLib.Data.eDataType.Int32)
            'LoTextCollection.Add("Desatinne cislo")
            'LoIdCollection.Add(KrosLib.Data.eDataType.Decimal)
            'LoTextCollection.Add("Text")
            'LoIdCollection.Add(KrosLib.Data.eDataType.Text)
            'LoTextCollection.Add("Datum")
            'LoIdCollection.Add(KrosLib.Data.eDataType.Date)
            'LoTextCollection.Add("Cas")
            'LoIdCollection.Add(KrosLib.Data.eDataType.Time)
            'LoTextCollection.Add("Datum a cas")
            'LoIdCollection.Add(KrosLib.Data.eDataType.DateTime)

            LoTextCollection.Add("Binary")
            LoIdCollection.Add(KrosLib.Data.eDataType.Binary)
            LoTextCollection.Add("Boolean")
            LoIdCollection.Add(KrosLib.Data.eDataType.Boolean)
            LoTextCollection.Add("Datum")
            LoIdCollection.Add(KrosLib.Data.eDataType.Date)
            LoTextCollection.Add("Datum/cas")
            LoIdCollection.Add(KrosLib.Data.eDataType.DateTime)
            LoTextCollection.Add("DB NULL")
            LoIdCollection.Add(KrosLib.Data.eDataType.DbNullValue)
            LoTextCollection.Add("Decimal")
            LoIdCollection.Add(KrosLib.Data.eDataType.Decimal)
            LoTextCollection.Add("Int32")
            LoIdCollection.Add(KrosLib.Data.eDataType.Int32)
            LoTextCollection.Add("Int64")
            LoIdCollection.Add(KrosLib.Data.eDataType.Int64)
            LoTextCollection.Add("Memo")
            LoIdCollection.Add(KrosLib.Data.eDataType.Memo)
            LoTextCollection.Add("Nothing")
            LoIdCollection.Add(KrosLib.Data.eDataType.NothingValue)
            LoTextCollection.Add("Object")
            LoIdCollection.Add(KrosLib.Data.eDataType.Object)
            LoTextCollection.Add("Text")
            LoIdCollection.Add(KrosLib.Data.eDataType.Text)
            LoTextCollection.Add("Cas")
            LoIdCollection.Add(KrosLib.Data.eDataType.Time)
            LoTextCollection.Add("Nedefinovane")
            LoIdCollection.Add(KrosLib.Data.eDataType.Undefined)


            MoUcnComboboxDataType = New UcnCombobox
            MoUcnComboboxDataType.Init("Datovy typ", LoTextCollection, , LoIdCollection)
            LoTextCollection.Clear()
            LoIdCollection.Clear()

            '--- ComponentType
            Dim LoDScomponentsSelected As DataRow() = MainForm.DScomponents.ComponentTable.Select(String.Format("{0}='{1}'", amod2.DsComponents.TableSysnames.Component.Columns.Selectable, 1))
            For Each LoRow As DataRow In LoDScomponentsSelected
                LoTextCollection.Add(LoRow("name"))
                LoIdCollection.Add(LoRow("number"))
            Next

            MoUcnComboboxComponentType = New UcnCombobox
            MoUcnComboboxComponentType.Init("Typ komponentu", LoTextCollection, , LoIdCollection)
            LoTextCollection.Clear()
            LoIdCollection.Clear()

            '--- Access
            LoTextCollection.Add("R/W")
            LoIdCollection.Add(KrosLib.Data.eFieldAccess.ReadWrite)
            LoTextCollection.Add("R")
            LoIdCollection.Add(KrosLib.Data.eFieldAccess.ReadOnly)

            MoUcnComboboxAccess = New UcnCombobox
            MoUcnComboboxAccess.Init("Pristup", LoTextCollection, , LoIdCollection)
            LoTextCollection.Clear()
            LoIdCollection.Clear()

            '--- ValidateType
            LoTextCollection.Add("-")
            LoIdCollection.Add(KrosLib.Data.eValidateType.None)
            LoTextCollection.Add("Zakladna")
            LoIdCollection.Add(KrosLib.Data.eValidateType.Basic)
            LoTextCollection.Add("Unikatnost")
            LoIdCollection.Add(KrosLib.Data.eValidateType.Unique)
            LoTextCollection.Add("Zakladna + Unikatnost")
            LoIdCollection.Add(KrosLib.Data.eValidateType.Combinate)

            MoUcnComboboxValidateType = New UcnCombobox
            MoUcnComboboxValidateType.Init("Kontrola", LoTextCollection, , LoIdCollection)
            LoTextCollection.Clear()
            LoIdCollection.Clear()


            SetReadyForUse(True) 'enabling usercontrol
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'initialization of controls
    Public Function Init(ByVal IoItem As DiagramItem, ByRef OoTable As DataTable, ByVal IoUcnComboboxJoinedModule As UcnCombobox, Optional ByVal IiSelectedPosition As Integer = 0, Optional ByVal IbDataNavigatorVisible As Boolean = True, Optional ByVal IbAddButtonEnabled As Boolean = True, Optional ByVal IbRemoveButtonEnabled As Boolean = True) As GeActionResult
        Try
            If MbReadyForUse Then
                If IiSelectedPosition <> -1 Then

                    'update data
                    CardView.BeginUpdate()
                    BindingSource.DataSource = OoTable
                    CardView.PopulateColumns(OoTable)
                    CardView.CardWidth = 100

                    MoItem = IoItem
                    MoUcnComboboxJoinedModule = IoUcnComboboxJoinedModule

                    If MoItem IsNot Nothing Then
                        Select Case MoItem.GetType.Name
                            Case "ClsMMTableNode"
                                DataNavigator.Position = IiSelectedPosition
                            Case Else
                                Debug.Print("CHYBA!!! - UcnGrid - Init")
                        End Select
                    End If

                    If IoItem IsNot Nothing Then
                        SetView()
                    End If

                    RaiseEvent MMPositionOfNavigatorChanged(DataNavigator.Position)

                    CardView.EndUpdate()
                    SetEnable()
                    DataNavigator.Visible = IbDataNavigatorVisible
                    DataNavigator.Buttons.CustomButtons(0).Enabled = IbAddButtonEnabled  'add button
                    DataNavigator.Buttons.CustomButtons(1).Enabled = IbRemoveButtonEnabled  'remove button

                    Return GeActionResult.kkOk
                Else
                    LogEvent("Neinicializovany UcnGrid! - POZICIA JE -1!", , )
                    Return GeActionResult.kkError
                End If
            Else
                LogEvent("Neinicializovany UcnGrid!", , )
                Return GeActionResult.kkError
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Properties"
#Region "Public attributes"
    Public ReadOnly Property ReadyForUse() As Boolean
        Get
            Return MbReadyForUse
        End Get
    End Property
    Public ReadOnly Property Position() As Integer
        Get
            If BindingSource.Count = 0 Then
                Return -1
            Else
                Return DataNavigator.Position
            End If
        End Get
    End Property
#End Region
#End Region
#Region "Events handler"
#Region "DataNavigator - Events handler"
    'adding, removing and moving rows of table
    Private Sub DataNavigator_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles DataNavigator.ButtonClick
        Select Case e.Button.ButtonType
            Case DevExpress.XtraEditors.NavigatorButtonType.Custom
                Select Case e.Button.Tag
                    Case "ADD_BUTTON"
                        e.Handled = True
                        RaiseEvent MMAddItem(MoItem, DataNavigator.Position + 2, CalculateNewPositionOfDataNavigator(DataNavigator.Position, 1))
                    Case "REMOVE_BUTTON"
                        e.Handled = True
                        RaiseEvent MMRemoveItem(MoItem, BindingSource.Current.row.Item("ColumnName"), CalculateNewPositionOfDataNavigator(DataNavigator.Position, -1))
                    Case "UP_BUTTON"
                        e.Handled = True
                        RaiseEvent MMMoveUp(MoItem, CType(BindingSource.Item(DataNavigator.Position), DataRow).Item("ColumnName"))
                    Case "DOWN_BUTTON"
                        e.Handled = True
                        RaiseEvent MMMoveDown(MoItem, CType(BindingSource.Item(DataNavigator.Position), DataRow).Item("ColumnName"))
                End Select
            Case DevExpress.XtraEditors.NavigatorButtonType.First
                RaiseEvent MMPositionOfNavigatorChanged(0)
            Case DevExpress.XtraEditors.NavigatorButtonType.Prev
                RaiseEvent MMPositionOfNavigatorChanged(DataNavigator.Position - 1)
            Case DevExpress.XtraEditors.NavigatorButtonType.Next
                RaiseEvent MMPositionOfNavigatorChanged(DataNavigator.Position + 1)
            Case DevExpress.XtraEditors.NavigatorButtonType.Last
                RaiseEvent MMPositionOfNavigatorChanged(BindingSource.Count - 1)
        End Select
    End Sub
#End Region
#Region "CardView - Events handler"

    Private Sub CardView_CustomDrawCardField(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles CardView.CustomDrawCardField
        RaiseEvent MMCustomDrawCardField(e)
    End Sub
    Private Sub CardView_CustomDrawCardFieldCaption(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles CardView.CustomDrawCardFieldCaption
        RaiseEvent MMCustomDrawCardFieldCaption(e)
    End Sub

    Private Sub CardView_CustomDrawCardFieldValue(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles CardView.CustomDrawCardFieldValue
        RaiseEvent MMCustomDrawCardFieldValue(e)
    End Sub
    'before activating an editor
    Private Sub CardView_ShowingEditor(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles CardView.ShowingEditor
        RaiseEvent MMShowingEditor(e)
    End Sub
    'saving old (original) value of cell for later use; addressing sub ImplicitBaseEditorEditValueChanged for immediate accepting changes after click on base editor of cell
    Private Sub CardView_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles CardView.ShownEditor
        Debug.Print("CardView_ShownEditor")
        MoOldCellValue = GridView.ActiveEditor.EditValue()

        If CardView.ActiveEditor.GetType.Name <> "TextEdit" Then
            MoImplicitBaseEditor = CardView.ActiveEditor
            AddHandler MoImplicitBaseEditor.EditValueChanged, AddressOf ImplicitBaseEditorEditValueChanged
        End If
    End Sub
    'removing event ImplicitRepository_EditorEditValueChanged
    Private Sub CardView_HiddenEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles CardView.HiddenEditor
        Debug.Print("CardView_HiddenEditor")
        If MoImplicitBaseEditor IsNot Nothing Then
            RemoveHandler MoImplicitBaseEditor.EditValueChanged, AddressOf ImplicitBaseEditorEditValueChanged
            MoImplicitBaseEditor = Nothing
        End If
    End Sub
    'changing value of cell
    Private Sub CardView_CellValueChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles CardView.CellValueChanged
        Debug.Print("CardView_CellValueChanged")
        CardView.UpdateCurrentRow()
        RaiseEvent MMValueChanged(e.Column, e.Value, MoOldCellValue)
    End Sub
    'value validating
    Private Sub CardView_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles CardView.ValidatingEditor
        Debug.Print("CardView_ValidatingEditor")
        e.Valid = False
        e.ErrorText = ""

        RaiseEvent MMValueValidating(MoItem, CardView.FocusedColumn, e.Value, e.Valid, e.ErrorText, MoOldCellValue)
    End Sub
    'response to an invalid cell value
    Private Sub CardView_InvalidValueException(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) Handles CardView.InvalidValueException
        RaiseEvent MMInvalidValueException(e)
    End Sub
#End Region
#Region "RepositoryItemComboBoxAccess - Events handler"
    Private Sub RepositoryItemComboBoxAccess_CustomDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs) Handles RepositoryItemComboBoxAccess.CustomDisplayText
        e.DisplayText = MoUcnComboboxAccess.GetPropertyValue(e.Value)
    End Sub
    Private Sub RepositoryItemComboBoxAccess_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles RepositoryItemComboBoxAccess.Popup
        MoUcnComboboxAccess.SelectRowByPropertyID(CardView.GetRowCellValue(CardView.FocusedRowHandle, CardView.FocusedColumn))
    End Sub
    Private Sub RepositoryItemComboBoxAccess_QueryResultValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.QueryResultValueEventArgs) Handles RepositoryItemComboBoxAccess.QueryResultValue
        e.Value = MoUcnComboboxAccess.Result
    End Sub
#End Region
#Region "RepositoryItemComboBoxComponentType - Events handler"
    Private Sub RepositoryItemComboBoxComponentType_CustomDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs) Handles RepositoryItemComboBoxComponentType.CustomDisplayText
        e.DisplayText = MoUcnComboboxComponentType.GetPropertyValue(e.Value)
    End Sub
    Private Sub RepositoryItemComboBoxComponentType_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles RepositoryItemComboBoxComponentType.Popup
        MoUcnComboboxComponentType.SelectRowByPropertyID(CardView.GetRowCellValue(CardView.FocusedRowHandle, CardView.FocusedColumn))
    End Sub
    Private Sub RepositoryItemComboBoxComponentType_QueryResultValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.QueryResultValueEventArgs) Handles RepositoryItemComboBoxComponentType.QueryResultValue
        e.Value = MoUcnComboboxComponentType.Result
    End Sub
#End Region
#Region "RepositoryItemComboBoxDataType - Events handler"
    Private Sub RepositoryItemComboBoxDataType_CustomDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs) Handles RepositoryItemComboBoxDataType.CustomDisplayText
        e.DisplayText = MoUcnComboboxDataType.GetPropertyValue(e.Value)
    End Sub
    Private Sub RepositoryItemComboBoxDataType_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles RepositoryItemComboBoxDataType.Popup
        MoUcnComboboxDataType.SelectRowByPropertyID(CardView.GetRowCellValue(CardView.FocusedRowHandle, CardView.FocusedColumn))
    End Sub
    Private Sub RepositoryItemComboBoxDataType_QueryResultValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.QueryResultValueEventArgs) Handles RepositoryItemComboBoxDataType.QueryResultValue
        e.Value = MoUcnComboboxDataType.Result
    End Sub
#End Region
#Region "RepositoryItemComboBoxJoinedModule - Events handler"
    Private Sub RepositoryItemComboBoxJoinedModule_CustomDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs) Handles RepositoryItemComboBoxJoinedModule.CustomDisplayText
        e.DisplayText = MoUcnComboboxJoinedModule.GetPropertyValue(e.Value)
    End Sub
    Private Sub RepositoryItemComboBoxJoinedModule_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles RepositoryItemComboBoxJoinedModule.Popup
        MoUcnComboboxJoinedModule.SelectRowByPropertyID(CardView.GetRowCellValue(CardView.FocusedRowHandle, CardView.FocusedColumn))
    End Sub
    Private Sub RepositoryItemComboBoxJoinedModule_QueryResultValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.QueryResultValueEventArgs) Handles RepositoryItemComboBoxJoinedModule.QueryResultValue
        e.Value = MoUcnComboboxJoinedModule.Result
    End Sub
#End Region
#Region "RepositoryItemComboBoxValidateType - Events handler"
    Private Sub RepositoryItemComboBoxValidateType_CustomDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs) Handles RepositoryItemComboBoxValidateType.CustomDisplayText
        e.DisplayText = MoUcnComboboxValidateType.GetPropertyValue(e.Value)
    End Sub
    Private Sub RepositoryItemComboBoxValidateType_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles RepositoryItemComboBoxValidateType.Popup
        MoUcnComboboxValidateType.SelectRowByPropertyID(CardView.GetRowCellValue(CardView.FocusedRowHandle, CardView.FocusedColumn))
    End Sub
    Private Sub RepositoryItemComboBoxValidateType_QueryResultValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.QueryResultValueEventArgs) Handles RepositoryItemComboBoxValidateType.QueryResultValue
        e.Value = MoUcnComboboxValidateType.Result
    End Sub
#End Region
#End Region
#Region "Subs"
    'sets MbReadyForUse attribute and sets Enable property of usercontrol
    Private Sub SetReadyForUse(ByVal IbValue As Boolean)
        MbReadyForUse = IbValue
        Me.Enabled = IbValue 'enabling usercontrol
    End Sub
    'sets names and visibility of columns
    Private Sub SetView()
        Try
            Dim LoCollectionOfVisibleColumns As Collection = New Collection
            Select Case MoItem.GetType.Name
                Case "ClsMMTableNode"
                    'set all columns as invisible
                    For Each LoColumn As GridColumn In CardView.Columns
                        LoColumn.Visible = False
                    Next

                    'set some columns as visible with special position
                    CardView.Columns("ResValue").Caption = "Analyticky nazov"
                    CardView.Columns("ResValue").VisibleIndex = 1
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("ResValue"), "ResValue")
                    CardView.Columns("ColumnName").Caption = "Programatorsky nazov"
                    CardView.Columns("ColumnName").VisibleIndex = 2
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("ColumnName"), "ColumnName")
                    CardView.Columns("DataType").Caption = "Datovy typ"
                    CardView.Columns("DataType").VisibleIndex = 3
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("DataType"), "DataType")
                    RepositoryItemComboBoxDataType.PopupControl = MoUcnComboboxDataType.PopupContainerControl
                    CardView.Columns("DataType").ColumnEdit = RepositoryItemComboBoxDataType
                    CardView.Columns("_a_ComponentType").Caption = "Typ komponentu"
                    CardView.Columns("_a_ComponentType").VisibleIndex = 4
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("_a_ComponentType"), "_a_ComponentType")
                    RepositoryItemComboBoxComponentType.PopupControl = MoUcnComboboxComponentType.PopupContainerControl
                    CardView.Columns("_a_ComponentType").ColumnEdit = RepositoryItemComboBoxComponentType
                    CardView.Columns("Description").Caption = "Popis"
                    CardView.Columns("Description").VisibleIndex = 5
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("Description"), "Description")
                    CardView.Columns("MinValue").Caption = "Min. hodnota"
                    CardView.Columns("MinValue").VisibleIndex = 6
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("MinValue"), "MinValue")
                    CardView.Columns("MaxValue").Caption = "Max. hodnota"
                    CardView.Columns("MaxValue").VisibleIndex = 7
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("MaxValue"), "MaxValue")
                    CardView.Columns("Length").Caption = "Dlzka retazca"
                    CardView.Columns("Length").VisibleIndex = 8
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("Length"), "Length")
                    CardView.Columns("Decimals").Caption = "Des. miesta"
                    CardView.Columns("Decimals").VisibleIndex = 9
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("Decimals"), "Decimals")
                    CardView.Columns("JoinModuleID").Caption = "Napojeny modul"
                    CardView.Columns("JoinModuleID").VisibleIndex = 10
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("JoinModuleID"), "JoinModuleID")
                    RepositoryItemComboBoxJoinedModule.PopupControl = MoUcnComboboxJoinedModule.PopupContainerControl
                    CardView.Columns("JoinModuleID").ColumnEdit = RepositoryItemComboBoxJoinedModule
                    CardView.Columns("DefaultValue").Caption = "Default"
                    CardView.Columns("DefaultValue").VisibleIndex = 11
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("DefaultValue"), "DefaultValue")
                    CardView.Columns("StrongBind").Caption = "Silna vazba"
                    CardView.Columns("StrongBind").VisibleIndex = 12
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("StrongBind"), "StrongBind")
                    CardView.Columns("Access").Caption = "Pristup"
                    CardView.Columns("Access").VisibleIndex = 13
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("Access"), "Access")
                    RepositoryItemComboBoxAccess.PopupControl = MoUcnComboboxAccess.PopupContainerControl
                    CardView.Columns("Access").ColumnEdit = RepositoryItemComboBoxAccess
                    CardView.Columns("ResShortValue").Caption = "Skratka"
                    CardView.Columns("ResShortValue").VisibleIndex = 14
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("ResShortValue"), "ResShortValue")
                    CardView.Columns("Validate").Caption = "Kontrola"
                    CardView.Columns("Validate").VisibleIndex = 15
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("Validate"), "Validate")
                    RepositoryItemComboBoxValidateType.PopupControl = MoUcnComboboxValidateType.PopupContainerControl
                    CardView.Columns("Validate").ColumnEdit = RepositoryItemComboBoxValidateType
                    CardView.Columns("ValidateText").Caption = "Text pri chybe"
                    CardView.Columns("ValidateText").VisibleIndex = 16
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("ValidateText"), "ValidateText")
                    CardView.Columns("Format").Caption = "Maska"
                    CardView.Columns("Format").VisibleIndex = 17
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("Format"), "Format")
                    CardView.Columns("_a_UsedInView").Caption = "Zobrazit v gride"
                    CardView.Columns("_a_UsedInView").VisibleIndex = 18
                    LoCollectionOfVisibleColumns.Add(CardView.Columns("_a_UsedInView"), "_a_UsedInView")
                Case Else
                    Debug.Print("CHYBA!!! - UcnGrid - SetView -  Select Case IsTableName")
            End Select
        Catch ex As Exception
            LogEventFromException(ex, , , )
        End Try
    End Sub
    'clear datasource
    Public Sub Clear()
        BindingSource.DataSource = Nothing
    End Sub
    'set enable settings for controls
    Private Sub SetEnable()
        DataNavigator.Buttons.CustomButtons(0).Enabled = True
        DataNavigator.Buttons.CustomButtons(1).Enabled = Not DataNavigator.Position = -1
        If BindingSource.DataSource IsNot Nothing Then
            ''''Dim LiNumberOfItems As Integer = 0
            '' ''Select Case BindingSource.DataSource.GetType.Name
            '' ''    Case "DataTable"
            '' ''LiNumberOfItems = CType(BindingSource.DataSource, DataTable).Columns.Count
            '' ''    Case "DataRow"
            '' ''LiNumberOfItems = 1
            '' ''    Case "Object[]"
            '' ''LiNumberOfItems = CType(BindingSource.DataSource, Object()).Count
            '' ''    Case Else
            '' ''LogEvent("Nedefinovany typ dat v UcnGrid")
            '' ''End Select

            DataNavigator.Buttons.CustomButtons(2).Enabled = DataNavigator.Position > 0
            ''''DataNavigator.Buttons.CustomButtons(3).Enabled = (DataNavigator.Position + 1 < LiNumberOfItems) And (LiNumberOfItems > 1)
            DataNavigator.Buttons.CustomButtons(3).Enabled = (DataNavigator.Position + 1 < BindingSource.DataSource.Columns.Count) And (BindingSource.DataSource.Columns.Count > 1)
        Else
            DataNavigator.Buttons.CustomButtons(2).Enabled = False
            DataNavigator.Buttons.CustomButtons(3).Enabled = False
        End If
    End Sub
    'sub for immediate accepting a changes made in implicit editor of cell
    Private Sub ImplicitBaseEditorEditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        CardView.PostEditor()
    End Sub
#End Region
#Region "Functions"
    'calculation of new position in DataNavigator after adding or removing row from grid
    Function CalculateNewPositionOfDataNavigator(ByVal IiOldPosition As Integer, ByVal IiCountChange As Integer) As Integer
        If IiCountChange = 1 Then Return IiOldPosition + 1 'if adding new row

        'if removing row
        If IiOldPosition = BindingSource.Count - 1 Then 'last row
            Return BindingSource.Count - 1 - 1
        Else
            Return IiOldPosition
        End If
    End Function
#End Region

End Class

'!!!!!!!!!!!!!!!!!!!!!!!!
'Private Sub gcGridControl_ProcessGridKey(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles gcGridControl.ProcessGridKey
